package com.easylive.web.controller;

import com.easylive.entity.constants.Constants;
import com.easylive.entity.dto.TokenUserInfoDto;
import com.easylive.entity.po.VideoDanmu;
import com.easylive.entity.po.VideoInfo;
import com.easylive.entity.query.VideoDanmuQuery;
import com.easylive.entity.query.VideoPlayHistoryQuery;
import com.easylive.entity.vo.ResponseVO;
import com.easylive.service.VideoDanmuService;
import com.easylive.service.VideoPlayHistoryService;
import com.easylive.service.impl.VideoInfoServiceImpl;
import com.easylive.web.annotation.GlobalInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.ArrayList;
import java.util.Date;


@RestController
@RequestMapping("/history")
@Slf4j
public class VideoPlayHistoryController extends ABaseController{

	@Autowired
	private VideoPlayHistoryService videoPlayHistoryService;

	@RequestMapping("/loadHistory")
	@GlobalInterceptor(checkLogin = true)
	public ResponseVO loadHistory(Integer pageNo){
		TokenUserInfoDto tokenUserInfoDto=getTokenUserInfoDto();
		VideoPlayHistoryQuery historyQuery=new VideoPlayHistoryQuery();
		historyQuery.setUserId(tokenUserInfoDto.getUserId());
		historyQuery.setOrderBy("last_update_time desc");
		historyQuery.setPageNo(pageNo);
		historyQuery.setQueryVideoDetail(true);
		return getSuccessResponseVO(videoPlayHistoryService.findListByPage(historyQuery));
	}

	@RequestMapping("/cleanHistory")
	@GlobalInterceptor(checkLogin = true)
	public ResponseVO cleanHistory(){
		TokenUserInfoDto tokenUserInfoDto=getTokenUserInfoDto();
		VideoPlayHistoryQuery historyQuery=new VideoPlayHistoryQuery();
		historyQuery.setUserId(tokenUserInfoDto.getUserId());
		videoPlayHistoryService.deleteByParam(historyQuery);
		return getSuccessResponseVO(null);
	}

	@RequestMapping("/delHistory")
	@GlobalInterceptor(checkLogin = true)
	public ResponseVO delHistory(@NotEmpty String videoId){
		TokenUserInfoDto tokenUserInfoDto=getTokenUserInfoDto();
		videoPlayHistoryService.deleteVideoPlayHistoryByUserIdAndVideoId(tokenUserInfoDto.getUserId(),videoId);
		return getSuccessResponseVO(null);
	}
}